package cq.com.cn.servlet;

import com.google.gson.Gson;
import cq.com.cn.model.BooksModel;
import cq.com.cn.service.BooksService;
import cq.com.cn.utils.AjaxUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/query/findBookbyName.do")
public class QueryBookByNameServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //参数处理
        String bookName=req.getParameter("bookName");
        //业务处理
        BooksService booksService=new BooksService();
        List<BooksModel> booksList = booksService.queryBooksByName(bookName);

        //数据返回到页面
        String books = new Gson().toJson(booksList);
        AjaxUtils.ajaxHtml(books,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
